package com.shop.service.impl;

import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.shop.entity.ShopProductTemplate;
import com.shop.mapper.ShopProductTemplateMapper;
import com.shop.service.ShopProductTemplateService;
import org.springframework.stereotype.Service;

/**
 * 服务层实现。
 *
 * @author 彭新才
 * @since 2024-10-12
 */
@Service
public class ShopProductTemplateServiceImpl extends ServiceImpl<ShopProductTemplateMapper, ShopProductTemplate> implements ShopProductTemplateService {

    @Override
    public boolean add(ShopProductTemplate shopProductTemplate) {
        String content = shopProductTemplate.getContent();
        ShopProductTemplate productTemplate = getOne(new QueryWrapper().eq(ShopProductTemplate::getContent, content));
        if (productTemplate != null) {
            throw new RuntimeException("已存证模板");
        }
        return save(shopProductTemplate);
    }
}
